<?php

class Dires_Utils {

	const PAGE_MESSAGE_ERROR = 1;
	const PAGE_MESSAGE_OK = 2;


	/**
	 *	Sets an error/ok message to be displayed on the next page. Note that after next page the message is lost, even if it hasn't been displayed.
	 *
	 *	@param string $message the message to be set
	 *	@param int $type optional the type of message (error or ok message)
	 */
	static function set_page_message($message, $type = self::PAGE_MESSAGE_ERROR) {
		if (!empty($message)) {
			if (is_array($message)) {
				$message = join('<br>', $message);
			}
			Session::instance()->set('page_message', array('message'=>$message, 'type'=>$type));
		}
	}

	/**
	 *	Gets the previously set page message
	 *
	 *	@return array the message, if any
	 */
	static function get_page_message() {
		$myreturn = Session::instance()->get('page_message');
		Session::instance()->delete('page_message');
		return $myreturn;
	}
}
